﻿using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

using Vector = Socium.Science.Vector;

namespace Socium.Documents.Sociograms {
	class RelationView : Shape {
		protected override Geometry DefiningGeometry {
			get {
				var a = new Point(X1, Y1);
				var b = new Point(X2, Y2);

				var cap = new Vector(CapWidth, CapHeight);
				return Arrow.GetGeometry(a, b, ArrowCaps.End, StrokeThickness, cap);
			}
		}

		public static readonly DependencyProperty CapWidthProperty = DependencyProperty.Register(
			"CapWidth",
			typeof (double),
			typeof (RelationView),
			new FrameworkPropertyMetadata(10d, FrameworkPropertyMetadataOptions.AffectsRender)
		);

		public static readonly DependencyProperty CapHeightProperty = DependencyProperty.Register(
			"CapHeight",
			typeof (double),
			typeof (RelationView),
			new FrameworkPropertyMetadata(10d, FrameworkPropertyMetadataOptions.AffectsRender)
		);

		public static readonly DependencyProperty X1Property = DependencyProperty.Register(
			"X1", 
			typeof (double),
			typeof (RelationView), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)
		);

		public static readonly DependencyProperty Y1Property = DependencyProperty.Register(
			"Y1",
			typeof (double),
			typeof (RelationView),
			new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)
		);

		public static readonly DependencyProperty X2Property = DependencyProperty.Register(
			"X2", 
			typeof (double),
			typeof (RelationView), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)
		);

		public static readonly DependencyProperty Y2Property = DependencyProperty.Register(
			"Y2",
			typeof (double),
			typeof (RelationView),
			new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)
		);

		public double Y1 {
			get { return (double) GetValue(Y1Property); }
			set { SetValue(Y1Property, value); }
		}

		public double X1 {
			get { return (double) GetValue(X1Property); }
			set { SetValue(X1Property, value); }
		}

		public double Y2 {
			get { return (double) GetValue(Y2Property); }
			set { SetValue(Y2Property, value); }
		}

		public double X2 {
			get { return (double) GetValue(X2Property); }
			set { SetValue(X2Property, value); }
		}

		public double CapHeight {
			get { return (double) GetValue(CapHeightProperty); }
			set { SetValue(CapHeightProperty, value); }
		}

		public double CapWidth {
			get { return (double) GetValue(CapWidthProperty); }
			set { SetValue(CapWidthProperty, value); }
		}
	}
}
